open(BUFF,"/data2/bsi/RandD/bora/tcga_genotyping/results/BRCA/NORMAL/testimputation/file_ahmed/before_imputation/test.tped") or die "no tped file found\n";
while(<BUFF>)
{
	chomp($_);
	@a = split(" ",$_);
	$hash{$a[1]} =1;
}
open(BUFF,"final_extra.dosage") or die "no file found\n";
open(WRBUFF1,">test1_dos") or die "not able to write test1\n";
@a = ();
while(<BUFF>)
{
        chomp($_);
	@a = split(" ",$_);
	if(exists($hash{$a[0]}))
	{
		#$hash{$a[0]} = 2;
		#print WRBUFF1 $a[0];
		$outline = "$a[0]";
		$m = 0;
		$n =0;
		if($a[2] eq "-")
                {
                	$a[2] =$a[1];
                }
		for($i=3;$i<@a;$i++)
		{
			$m++;
			$gnt1 = $a[$i];
			$i++;
			$gnt2 = $a[$i];
			if($gnt1 eq "1" && $gnt2 eq "0")
			{
				#print WRBUFF1 " $a[1] $a[1]";
				$outline =$outline." $a[1] $a[1]";
			}
			elsif($gnt1 eq "0" && $gnt2 eq "1")
                        {
                                #print WRBUFF1 " $a[1] $a[2]";
				$outline =$outline." $a[1] $a[2]";
                        }
			elsif($gnt1 eq "0" && $gnt2 eq "0")
                        {
                                #print WRBUFF1 " $a[2] $a[2]";
				$outline =$outline." $a[2] $a[2]";
                        }
			else
			{
				$n++;
                                #print WRBUFF1 " 0 0";
				$outline =$outline." 0 0";
                        }
		}
		if($m != $n)
		{
			print WRBUFF1 $outline."\n";
			$hash{$a[0]} = 2;
		}
		#print WRBUFF1 "\n";
	}
}
open(BUFF,"/data2/bsi/RandD/bora/tcga_genotyping/results/BRCA/NORMAL/testimputation/file_ahmed/before_imputation/test.tped") or die "no tped file found\n";
open(WRBUFF1,">test2_ori") or die "not able to write test2\n";
while(<BUFF>)
{
        chomp($_);
        @a = split(" ",$_);
	if($hash{$a[1]} == 2)
	{
		shift(@a);
		$rsid = shift(@a);
		shift(@a);
		shift(@a);
		print WRBUFF1 $rsid;
		$_ = join(" ",@a);
		print WRBUFF1 " $_\n";
	}
}
open(BUFF,"mostLikelyGenotypes_final.tped") or die "no tped file found\n";
open(WRBUFF1,">test3_ahmed") or die "not able to write test2\n";
while(<BUFF>)
{
        chomp($_);
        @a = split(" ",$_);
        if($hash{$a[1]} == 2)
        {
                shift(@a);
                $rsid = shift(@a);
                shift(@a);
                shift(@a);
                print WRBUFF1 $rsid;
                $_ = join(" ",@a);
                print WRBUFF1 " $_\n";
        }
}

#system("sort -k1,1 test1_dos > test3_dos");
#system("sort -k1,1 test2_ori > test4_ori");
